﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAC.sqlHelper;
using SAC.Helper;
using SAC.Power;
using SAC.DB2;
using System.Collections;
using System.Data;
using SAC.DAL.PublicMethod;

namespace SAC.DAL.DayRep
{
    /// <summary>
    /// 日报表 
    /// </summary>
    public class DayRep
    {
        int count;
        int countKey;
        string sql = "";
        string errMsg = "";
        string TSMS = "";       //调试模式
        string rtDBType = "";   //实时数据库
        string rlDBType = "";   //关系数据库

        SAC.Elink.Elink ek = new SAC.Elink.Elink();
        SAC.Plink.Plink pk = new SAC.Plink.Plink();
        StrHelper sh = new StrHelper();
        PowerCale pc = new PowerCale();
        DALPubMehtod pm = new DALPubMehtod();
        DALUtilityMehtod um = new DALUtilityMehtod();
        LogHelper lh = new LogHelper();


        /// <summary>
        /// 初始化函数
        /// 初始化报表配置
        /// 对全局变量赋值
        /// </summary>
        /// <returns></returns>
        private void init()
        {
            TSMS = IniHelper.ReadIniData("Report", "TSMS", null);
            rtDBType = IniHelper.ReadIniData("RTDB", "DBType", null);
            rlDBType = IniHelper.ReadIniData("RelationDBbase", "DBType", null);
        }

        /// <summary>
        /// 日报
        /// 机组轮转
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <returns></returns>
        public ArrayList RetArrsRepDay(string repName, string repType, string qsrq, string jsrq, bool isDay)
        {
            this.init();

            object obj;
            string bm = "";     //电量表码
            string mon = "";    //计算公式
            string res = "";    //计算结果
            string num = "";    //小数点数
            string unit = "";   //机组编码
            string dlID = "";   //电量ID
            string pName = "";  //测点名称
            string sDate = "";  //结束时间(实时值,SQL结束时间)
            string gsjb = "";   //公式级别
            string GYID = "";   //公用库参数ID
            string ParaID = ""; //参数ID

            int id;
            int ret = 0;
            double drvA = 0;
            double valGY = 0;

            //基础数据值
            string[] zb = null;
            string[] un = null;
            string[] lay = null;
            string[] dv = null;
            string[] dvExcel = null;

            DataTable dtGY = null;
            DataTable dtLel = null;     //机组级别
            DataTable dtLevZ = null;    //全厂级别
            DataTable dtLevUnit = null;
            Hashtable htGY = new Hashtable();
            Hashtable htUn = new Hashtable();
            ArrayList list = new ArrayList();

            count = pm.GetCount(repName);

            zb = new string[count + 1];
            un = new string[count + 1];
            lay = new string[count + 1];
            dv = new string[count + 1];
            dvExcel = new string[count + 1];

            if (isDay == true)
                sDate = DateTime.Parse(jsrq).ToString("yyyy-MM-dd H:59:59");
            else
                sDate = DateTime.Parse(jsrq).AddSeconds(-1).ToString("yyyy-MM-dd H:mm:ss");

            if (rtDBType == "PI")
                SAC.Plink.Plink.OpenPi();

            #region 公用库读取
            sql = "select * from GYReport where 报表名称='全厂级'";

            if (rlDBType == "SQL")
                dtGY = DBsql.RunDataTable(sql, out errMsg);
            else
                dtGY = DBdb2.RunDataTable(sql, out errMsg);

            if (dtGY != null && dtGY.Rows.Count > 0)
            {
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----公用库轮转开始!");

                for (int i = 0; i < dtGY.Rows.Count; i++)
                {
                    GYID = dtGY.Rows[i]["参数ID"].ToString();

                    if (dtGY.Rows[i][9].ToString() == "平均" || dtGY.Rows[i][9].ToString() == "累计")
                    {
                        pName = dtGY.Rows[i][repType].ToString();

                        if (rtDBType == "PI")
                            pk.GetHisValue(pName, sDate, ref valGY);
                        else if (rtDBType == "EDNA")
                            ek.GetHisValueByTime(pName, sDate, ref ret, ref valGY);

                        if (GYID != "")
                        {
                            if (htGY.Contains(GYID))
                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + GYID + "----在公用库和报表配置表中有重复记录...");
                            else
                                htGY.Add(GYID, valGY);
                        }
                    }
                    else if (dtGY.Rows[i][9].ToString() == "电量")
                    {
                        dlID = dtGY.Rows[i]["电量点"].ToString();

                        valGY = double.Parse(pc.GetPower(valGY, dlID, qsrq, jsrq, bm).ToString());

                        mon = "";

                        if (dtGY.Rows[i]["公式"].ToString() != "")
                            mon = valGY.ToString() + dtGY.Rows[i]["公式"].ToString();
                        else
                            mon = valGY.ToString();

                        res = "";
                        try
                        { res = StrHelper.Cale(mon); }
                        catch
                        { res = "0"; }

                        if (GYID != "")
                        {
                            if (htGY.Contains(GYID))
                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + GYID + "----在公用库和报表配置表中有重复记录...");
                            else
                                htGY.Add(GYID, res);
                        }
                    }
                    else if (dtGY.Rows[i][9].ToString() == "SQL")
                    {
                        sql = dtGY.Rows[i]["SQL语句"].ToString();

                        if (sql.Contains("&bt&") && sql.Contains("&et&"))
                        {
                            sql = sql.Replace("&bt&", qsrq);
                            sql = sql.Replace("&et&", sDate);
                        }

                        if (rlDBType == "SQL")
                            obj = DBsql.RunSingle(sql, out errMsg);
                        else
                            obj = DBdb2.RunSingle(sql, out errMsg);

                        res = "";
                        if (obj != null && obj != "")
                        {
                            if (obj.ToString() != "")
                                res = obj.ToString();
                            else
                                res = "0";
                        }
                        else
                        { res = "0"; }

                        if (GYID != "")
                        {
                            if (htGY.Contains(GYID))
                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + GYID + "----在公用库和报表配置表中有重复记录...");
                            else
                                htGY.Add(GYID, res);
                        }
                    }
                }
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----公用库轮转结束!");
            }
            #endregion

            #region 机组数据读取

            sql = "SELECT DISTINCT 机组 FROM T_sheet_sheetPara where 报表名称='" + repName + "' and 机组!=0";

            if (rlDBType == "SQL")
                dtLevUnit = DBsql.RunDataTable(sql, out errMsg);
            else if (rlDBType == "DB2")
                dtLevUnit = DBdb2.RunDataTable(sql, out errMsg);

            if (dtLevUnit != null && dtLevUnit.Rows.Count > 0)
            {
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----机组轮转开始!");

                for (int k = 0; k < dtLevUnit.Rows.Count; k++)
                {
                    unit = dtLevUnit.Rows[k]["机组"].ToString();

                    sql = "SELECT DISTINCT 公式级别 FROM T_sheet_sheetPara where 报表名称='" + repName + "' and 机组!=0 and 公式级别!=0";

                    if (rlDBType == "SQL")
                        dtLel = DBsql.RunDataTable(sql, out errMsg);
                    else if (rlDBType == "DB2")
                        dtLel = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtLel.Rows.Count > 0)
                    {
                        for (int j = 0; j < dtLel.Rows.Count; j++)
                        {
                            //公式级别
                            gsjb = dtLel.Rows[j]["公式级别"].ToString();

                            #region 平均
                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='平均' and 公式级别=" + gsjb;

                            DataTable dtAvg = null;

                            if (rlDBType == "SQL")
                                dtAvg = DBsql.RunDataTable(sql, out errMsg);
                            else if (rlDBType == "DB2")
                                dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtAvg != null && dtAvg.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtAvg.Rows.Count; i++)
                                {
                                    //小数点
                                    num = dtAvg.Rows[i]["小数点数"].ToString();
                                    //点名
                                    pName = dtAvg.Rows[i][repType].ToString();
                                    //参数ID
                                    ParaID = dtAvg.Rows[i]["参数ID"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());

                                    if (rtDBType == "EDNA")
                                        ek.GetHisValueByTime(pName, sDate, ref ret, ref drvA);
                                    else if (rtDBType == "PI")
                                        pk.GetHisValue(pName, sDate, ref drvA);

                                    if (id != 0)
                                    {
                                        zb[id] = dtAvg.Rows[i]["参数名"].ToString();
                                        un[id] = dtAvg.Rows[i]["单位"].ToString();
                                        lay[id] = dtAvg.Rows[i]["设计值"].ToString();

                                        dv[id] += sh.ShowPoint(drvA.ToString(), num) + ",";
                                        dvExcel[id] += drvA.ToString() + ",";
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.ContainsKey(ParaID))
                                            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                        else
                                            htUn.Add(ParaID, drvA.ToString());
                                    }
                                }
                            }
                            #endregion

                            #region 累计
                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='累计' and 公式级别=" + gsjb;

                            DataTable dtDiff = null;

                            if (rlDBType == "SQL")
                                dtDiff = DBsql.RunDataTable(sql, out errMsg);
                            else if (rlDBType == "DB2")
                                dtDiff = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtDiff != null && dtDiff.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtDiff.Rows.Count; i++)
                                {
                                    num = dtDiff.Rows[i]["小数点数"].ToString();

                                    pName = dtDiff.Rows[i][repType].ToString();
                                    //参数ID
                                    ParaID = dtDiff.Rows[i]["参数ID"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtDiff.Rows[i]["参数顺序"].ToString());

                                    if (rtDBType == "EDNA")
                                        ek.GetHisValueByTime(pName, sDate, ref ret, ref drvA);
                                    else if (rtDBType == "PI")
                                        pk.GetHisValue(pName, sDate, ref drvA);

                                    if (id != 0)
                                    {
                                        zb[id] = dtDiff.Rows[i]["参数名"].ToString();
                                        un[id] = dtDiff.Rows[i]["单位"].ToString();
                                        lay[id] = dtDiff.Rows[i]["设计值"].ToString();

                                        dv[id] += sh.ShowPoint(drvA.ToString(), num) + ",";
                                        dvExcel[id] += drvA.ToString() + ",";
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.ContainsKey(ParaID))
                                            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                        else
                                            htUn.Add(ParaID, drvA.ToString());
                                    }
                                }
                            }

                            #endregion

                            #region SQL

                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='SQL' and 公式级别=" + gsjb;

                            DataTable dtSQL = null;

                            if (rlDBType == "SQL")
                                dtSQL = DBsql.RunDataTable(sql, out errMsg);
                            else
                                dtSQL = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtSQL != null && dtSQL.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtSQL.Rows.Count; i++)
                                {
                                    num = dtSQL.Rows[i]["小数点数"].ToString();
                                    //参数ID
                                    ParaID = dtSQL.Rows[i]["参数ID"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtSQL.Rows[i]["参数顺序"].ToString());

                                    sql = dtSQL.Rows[i]["SQL语句"].ToString();

                                    if (sql.Contains("&bt&") && sql.Contains("&et&"))
                                    {
                                        sql = sql.Replace("&bt&", qsrq);
                                        sql = sql.Replace("&et&", sDate);
                                    }

                                    if (rlDBType == "SQL")
                                        obj = DBsql.RunSingle(sql, out errMsg);
                                    else
                                        obj = DBdb2.RunSingle(sql, out errMsg);

                                    res = "";
                                    if (obj != null && obj != "")
                                    {
                                        if (obj.ToString() != "")
                                            res = obj.ToString();
                                        else
                                            res = "0";
                                    }
                                    else
                                    { res = "0"; }

                                    if (id != 0)
                                    {
                                        zb[id] = dtSQL.Rows[i]["参数名"].ToString();
                                        un[id] = dtSQL.Rows[i]["单位"].ToString();
                                        lay[id] = dtSQL.Rows[i]["设计值"].ToString();

                                        dv[id] += sh.ShowPoint(res, num) + ",";
                                        dvExcel[id] += sh.ShowPoint(res, "-1") + ",";
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.ContainsKey(ParaID))
                                            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                        else
                                            htUn.Add(ParaID, res);
                                    }
                                }
                            }
                            #endregion

                            #region 电量
                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='电量' and 公式级别=" + gsjb;

                            DataTable dtDL = null;
                            if (rlDBType == "SQL")
                                dtDL = DBsql.RunDataTable(sql, out errMsg);
                            else
                                dtDL = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtDL.Rows.Count > 0 && dtDL != null)
                            {
                                for (int i = 0; i < dtDL.Rows.Count; i++)
                                {
                                    num = dtDL.Rows[i]["小数点数"].ToString();

                                    //参数ID
                                    ParaID = dtDL.Rows[i]["参数ID"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());

                                    dlID = dtDL.Rows[i]["电量点"].ToString();

                                    drvA = double.Parse(pc.GetPower(drvA, dlID, qsrq, jsrq, bm).ToString());

                                    mon = "";

                                    if (dtDL.Rows[i]["公式"].ToString() != "")
                                        mon = drvA.ToString() + dtDL.Rows[i]["公式"].ToString();
                                    else
                                        mon = drvA.ToString();

                                    res = "";
                                    try
                                    { res = StrHelper.Cale(mon); }
                                    catch
                                    { res = "0"; }

                                    if (id != 0)
                                    {
                                        //zb[id] = dtSQL.Rows[i]["参数名"].ToString();
                                        //un[id] = dtSQL.Rows[i]["单位"].ToString();
                                        //lay[id] = dtSQL.Rows[i]["设计值"].ToString();

                                        #region 2012/09/13 胡进财 修改
                                        zb[id] = dtDL.Rows[i]["参数名"].ToString();
                                        un[id] = dtDL.Rows[i]["单位"].ToString();
                                        lay[id] = dtDL.Rows[i]["设计值"].ToString();
                                        #endregion

                                        dv[id] += sh.ShowPoint(res, num) + ",";
                                        dvExcel[id] += sh.ShowPoint(res, "-1") + ",";
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.ContainsKey(ParaID))
                                            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                        else
                                            htUn.Add(ParaID, res);
                                    }
                                }
                            }

                            #endregion

                            #region 其它
                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='其它' and 公式级别=" + gsjb;

                            DataTable dtQT = null;

                            if (rlDBType == "SQL")
                                dtQT = DBsql.RunDataTable(sql, out errMsg);
                            else
                                dtQT = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtQT.Rows.Count > 0 && dtQT != null)
                            {
                                for (int i = 0; i < dtQT.Rows.Count; i++)
                                {
                                    //小数点
                                    num = dtQT.Rows[i]["小数点数"].ToString();
                                    //参数ID
                                    ParaID = dtQT.Rows[i]["参数ID"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());
                                    //点名
                                    pName = dtQT.Rows[i][repType].ToString();

                                    #region 购网电量
                                    if (dtQT.Rows[i]["参数名"].ToString() == "购网电量")
                                    {
                                        string re = um.gwdl(qsrq, jsrq, int.Parse(unit));

                                        if (id != 0)
                                        {
                                            zb[id] = dtSQL.Rows[i]["参数名"].ToString();
                                            un[id] = dtSQL.Rows[i]["单位"].ToString();
                                            lay[id] = dtSQL.Rows[i]["设计值"].ToString();

                                            dv[id] += sh.ShowPoint(re.ToString(), num) + ",";
                                            dvExcel[id] += sh.ShowPoint(re.ToString(), "-1") + ",";
                                        }

                                        if (ParaID != "")
                                        {
                                            if (htUn.ContainsKey(ParaID))
                                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                            else
                                                htUn.Add(ParaID, re);
                                        }
                                    }
                                    #endregion

                                    #region 入炉煤低位发热量
                                    if (dtQT.Rows[i]["参数名"].ToString() == "入炉煤低位发热量")
                                    {
                                        string rlm = um.rlmdwfrl("日报", qsrq, jsrq, 1);

                                        if (id != 0)
                                        {
                                            zb[id] = dtQT.Rows[i]["参数名"].ToString();
                                            un[id] = dtQT.Rows[i]["单位"].ToString();
                                            lay[id] = dtQT.Rows[i]["设计值"].ToString();

                                            dv[id] += sh.ShowPoint(rlm, num) + ",";
                                            dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                        }


                                        if (ParaID != "")
                                        {
                                            if (htUn.ContainsKey(ParaID))
                                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                            else
                                                htUn.Add(ParaID, rlm);
                                        }
                                    }
                                    #endregion

                                    #region 燃料耗量
                                    if (dtQT.Rows[i]["参数名"].ToString().Remove(0, dtQT.Rows[i]["参数名"].ToString().Length - 2) == "早班" || dtQT.Rows[i]["参数名"].ToString().Remove(0, dtQT.Rows[i]["参数名"].ToString().Length - 2) == "中班" || dtQT.Rows[i]["参数名"].ToString().Remove(0, dtQT.Rows[i]["参数名"].ToString().Length - 2) == "晚班")
                                    {
                                        string rlm = "";
                                        DataTable dtrlhl = new DataTable();
                                        sql = "SELECT * FROM ADMINISTRATOR.班次时间表 where 班次编号='1'";

                                        if (rlDBType == "SQL")
                                            dtrlhl = DBsql.RunDataTable(sql, out errMsg);
                                        else if (rlDBType == "DB2")
                                            dtrlhl = DBdb2.RunDataTable(sql, out errMsg);

                                        sql = "SELECT sum(统计值) as 统计值 FROM ADMINISTRATOR.实时统计数据表1 where 统计ID='" + pName + "' and 时间>'" + Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + dtrlhl.Rows[0]["起始时间"]) + "' and 时间<='" + Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + dtrlhl.Rows[0]["结束时间"]) + "'";

                                        if (rlDBType == "SQL")
                                            dtrlhl = DBsql.RunDataTable(sql, out errMsg);
                                        else if (rlDBType == "DB2")
                                            dtrlhl = DBdb2.RunDataTable(sql, out errMsg);

                                        //if (id != 0)
                                        //{
                                        zb[id] = dtQT.Rows[i]["参数名"].ToString();
                                        un[id] = dtQT.Rows[i]["单位"].ToString();
                                        lay[id] = dtQT.Rows[i]["设计值"].ToString();

                                        if (dtrlhl != null && dtrlhl.Rows.Count > 0)
                                        {
                                            rlm = dtrlhl.Rows[0]["统计值"].ToString();
                                            dv[id] += sh.ShowPoint(rlm, num) + ",";
                                            dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                        }
                                        else
                                        {
                                            dv[id] += "0,";
                                            dvExcel[id] += "0,";
                                        }
                                        //}


                                        if (ParaID != "")
                                        {
                                            if (htUn.ContainsKey(ParaID))
                                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                            else
                                                htUn.Add(ParaID, rlm);
                                        }
                                    }
                                    #endregion
                                }
                            }
                            #endregion

                            #region 峰谷比
                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型 in('峰','尖','谷' ,'平') and 公式级别=" + gsjb;

                            dtAvg = null;

                            if (rlDBType == "SQL")
                                dtAvg = DBsql.RunDataTable(sql, out errMsg);
                            else if (rlDBType == "DB2")
                                dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtAvg != null && dtAvg.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtAvg.Rows.Count; i++)
                                {
                                    //小数点
                                    num = dtAvg.Rows[i]["小数点数"].ToString();
                                    //点名
                                    pName = dtAvg.Rows[i][repType].ToString();
                                    //参数ID
                                    ParaID = dtAvg.Rows[i]["参数ID"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());

                                    string point = dtAvg.Rows[i]["电量点"].ToString();

                                    if (dtAvg.Rows[i]["参数类型"].ToString() == "峰")
                                    {
                                        res = getDlFGB(point, qsrq, jsrq, "峰");
                                        drvA = Convert.ToDouble(res.Split('|')[0]);
                                    }

                                    if (dtAvg.Rows[i]["参数类型"].ToString() == "平")
                                    {
                                        res = getDlFGB(point, qsrq, jsrq, "平");
                                        drvA = Convert.ToDouble(res.Split('|')[1]);
                                    }
                                    if (dtAvg.Rows[i]["参数类型"].ToString() == "谷")
                                    {
                                        res = getDlFGB(point, qsrq, jsrq, "谷");
                                        drvA = Convert.ToDouble(res.Split('|')[2]);
                                    }
                                    if (dtAvg.Rows[i]["参数类型"].ToString() == "尖")
                                    {
                                        res = getDlFGB(point, qsrq, jsrq, "尖");
                                        drvA = Convert.ToDouble(res.Split('|')[3]);
                                    }

                                    if (id != 0)
                                    {
                                        zb[id] = dtAvg.Rows[i]["参数名"].ToString();
                                        un[id] = dtAvg.Rows[i]["单位"].ToString();
                                        lay[id] = dtAvg.Rows[i]["设计值"].ToString();

                                        dv[id] += sh.ShowPoint(drvA.ToString(), num) + ",";
                                        dvExcel[id] += drvA.ToString() + ",";
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.Contains(ParaID))
                                        {
                                            string str = htUn[ParaID] + drvA.ToString() + ",";
                                            htUn.Remove(ParaID);
                                            htUn.Add(ParaID, str);
                                        }
                                        else
                                        {
                                            htUn.Add(ParaID, drvA.ToString());
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region 存储过程

                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='存储过程' and 公式级别=" + gsjb;

                            DataTable dtSP = null;

                            if (rlDBType == "SQL")
                                dtSP = DBsql.RunDataTable(sql, out errMsg);
                            else
                                dtSP = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtSP != null && dtSP.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtSP.Rows.Count; i++)
                                {
                                    //小数点数
                                    num = dtSP.Rows[i]["小数点数"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtSP.Rows[i]["参数顺序"].ToString());
                                    //参数ID
                                    ParaID = dtSP.Rows[i]["参数ID"].ToString();

                                    string spName = dtSP.Rows[i]["SQL语句"].ToString();

                                    if (rlDBType == "SQL")
                                        obj = DBsql.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), qsrq, jsrq, "", out errMsg);
                                    else
                                        obj = DBdb2.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), qsrq, jsrq, "", out errMsg);

                                    if (obj != null && obj.ToString() != "")
                                    {
                                        if (obj.ToString() != "")
                                            res = obj.ToString();
                                        else
                                            res = "0";
                                    }
                                    else
                                    { res = "0"; }

                                    if (id != 0)
                                    {
                                        zb[id] = dtSP.Rows[i]["参数名"].ToString();
                                        un[id] = dtSP.Rows[i]["单位"].ToString();
                                        lay[id] = dtSP.Rows[i]["设计值"].ToString();

                                        dv[id] += sh.ShowPoint(res, num) + ",";
                                        dvExcel[id] += res + ",";
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.ContainsKey(ParaID))
                                        {
                                            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                        }
                                        else
                                            htUn.Add(ParaID, res);
                                    }

                                }
                            }
                            #endregion

                            #region 公式
                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='公式' and 公式级别=" + gsjb;

                            DataTable dtMon = null;

                            if (rlDBType == "SQL")
                                dtMon = DBsql.RunDataTable(sql, out errMsg);
                            else
                                dtMon = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtMon != null && dtMon.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtMon.Rows.Count; i++)
                                {
                                    //小数点数
                                    num = dtMon.Rows[i]["小数点数"].ToString();
                                    //参数ID
                                    ParaID = dtMon.Rows[i]["参数ID"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());

                                    string pMon = dtMon.Rows[i]["公式"].ToString();

                                    string paras = dtMon.Rows[i]["公式参数"].ToString();

                                    string month = pm.retMon(htGY, htUn, paras, pMon);

                                    if (month != "")
                                    {
                                        res = "";
                                        try
                                        {
                                            res = StrHelper.Cale(month);

                                            if (id != 0)
                                                dvExcel[id] += sh.ShowPoint(res, "-1") + ",";

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                                else
                                                    htUn.Add(ParaID, res);
                                            }

                                            res = sh.ShowPoint(res, num);
                                        }
                                        catch
                                        { res = "0"; }

                                        if (id != 0)
                                        {
                                            zb[id] = dtMon.Rows[i]["参数名"].ToString();
                                            un[id] = dtMon.Rows[i]["单位"].ToString();
                                            lay[id] = dtMon.Rows[i]["设计值"].ToString();
                                            dv[id] += sh.ShowPoint(res, num) + ",";
                                        }
                                    }
                                }
                            }

                            #endregion

                        }
                    }
                }
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----机组轮转结束!");
            }
            #endregion

            #region 全厂数据读取

            sql = "SELECT DISTINCT 公式级别 FROM T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 公式级别!=0";

            if (rlDBType == "SQL")
                dtLevZ = DBsql.RunDataTable(sql, out errMsg);
            else
                dtLevZ = DBdb2.RunDataTable(sql, out errMsg);

            if (dtLevZ.Rows.Count > 0)
            {
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----全厂开始!");

                for (int j = 0; j < dtLevZ.Rows.Count; j++)
                {
                    gsjb = dtLevZ.Rows[j]["公式级别"].ToString();

                    #region 平均
                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='平均' and 公式级别=" + gsjb;

                    DataTable dtAvg = null;

                    if (rlDBType == "SQL")
                        dtAvg = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtAvg != null && dtAvg.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtAvg.Rows.Count; i++)
                        {
                            //小数点
                            num = dtAvg.Rows[i]["小数点数"].ToString();
                            //点名
                            pName = dtAvg.Rows[i][repType].ToString();
                            //参数ID
                            ParaID = dtAvg.Rows[i]["参数ID"].ToString();
                            //参数顺序
                            id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());

                            if (rtDBType == "EDNA")
                                ek.GetHisValueByTime(pName, sDate, ref ret, ref drvA);
                            else
                                pk.GetHisValue(pName, sDate, ref drvA);

                            if (id != 0)
                            {
                                zb[id] = dtAvg.Rows[i]["参数名"].ToString();
                                un[id] = dtAvg.Rows[i]["单位"].ToString();
                                lay[id] = dtAvg.Rows[i]["设计值"].ToString();

                                dv[id] += sh.ShowPoint(drvA.ToString(), num) + ",";
                                dvExcel[id] += drvA.ToString() + ",";
                            }

                            if (ParaID != "")
                            {
                                if (htUn.ContainsKey(ParaID))
                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                else
                                    htUn.Add(ParaID, drvA.ToString());
                            }
                        }
                    }
                    #endregion

                    #region 累计
                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='累计' and 公式级别=" + gsjb;

                    DataTable dtDiff = null;

                    if (rlDBType == "SQL")
                        dtDiff = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtDiff = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtDiff != null && dtDiff.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtDiff.Rows.Count; i++)
                        {
                            num = dtDiff.Rows[i]["小数点数"].ToString();

                            pName = dtDiff.Rows[i][repType].ToString();
                            //参数ID
                            ParaID = dtDiff.Rows[i]["参数ID"].ToString();
                            //参数顺序
                            id = int.Parse(dtDiff.Rows[i]["参数顺序"].ToString());

                            if (rtDBType == "EDNA")
                                ek.GetHisValueByTime(pName, sDate, ref ret, ref drvA);
                            else
                                pk.GetHisValue(pName, sDate, ref drvA);

                            if (id != 0)
                            {
                                zb[id] = dtDiff.Rows[i]["参数名"].ToString();
                                un[id] = dtDiff.Rows[i]["单位"].ToString();
                                lay[id] = dtDiff.Rows[i]["设计值"].ToString();

                                dv[id] += sh.ShowPoint(drvA.ToString(), num) + ",";
                                dvExcel[id] += drvA.ToString() + ",";
                            }

                            if (ParaID != "")
                            {
                                if (htUn.ContainsKey(ParaID))
                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                else
                                    htUn.Add(ParaID, drvA.ToString());
                            }
                        }
                    }

                    #endregion

                    #region SQL

                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='SQL' and 公式级别=" + gsjb;

                    DataTable dtSQL = null;
                    if (rlDBType == "SQL")
                        dtSQL = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtSQL = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtSQL != null && dtSQL.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtSQL.Rows.Count; i++)
                        {
                            num = dtSQL.Rows[i]["小数点数"].ToString();
                            //参数ID
                            ParaID = dtSQL.Rows[i]["参数ID"].ToString();
                            //参数顺序
                            id = int.Parse(dtSQL.Rows[i]["参数顺序"].ToString());

                            sql = dtSQL.Rows[i]["SQL语句"].ToString();

                            if (sql.Contains("&bt&") && sql.Contains("&et&"))
                            {
                                sql = sql.Replace("&bt&", qsrq);
                                sql = sql.Replace("&et&", sDate);
                            }

                            if (rlDBType == "SQL")
                                obj = DBsql.RunSingle(sql, out errMsg);
                            else
                                obj = DBdb2.RunSingle(sql, out errMsg);

                            res = "";
                            if (obj != null && obj != "")
                            {
                                if (obj.ToString() != "")
                                    res = obj.ToString();
                                else
                                    res = "0";
                            }
                            else
                            { res = "0"; }

                            if (id != 0)
                            {
                                zb[id] = dtSQL.Rows[i]["参数名"].ToString();
                                un[id] = dtSQL.Rows[i]["单位"].ToString();
                                lay[id] = dtSQL.Rows[i]["设计值"].ToString();

                                dv[id] += sh.ShowPoint(res, num) + ",";
                                dvExcel[id] += sh.ShowPoint(res, "-1") + ",";
                            }

                            if (ParaID != "")
                            {
                                if (htUn.ContainsKey(ParaID))
                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                else
                                    htUn.Add(ParaID, res);
                            }
                        }
                    }
                    #endregion

                    #region 电量
                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='电量' and 公式级别=" + gsjb;

                    DataTable dtDL = null;

                    if (rlDBType == "SQL")
                        dtDL = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtDL = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtDL.Rows.Count > 0 && dtDL != null)
                    {
                        for (int i = 0; i < dtDL.Rows.Count; i++)
                        {
                            num = dtDL.Rows[i]["小数点数"].ToString();

                            //参数ID
                            ParaID = dtDL.Rows[i]["参数ID"].ToString();
                            //参数顺序
                            id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());

                            dlID = dtDL.Rows[i]["电量点"].ToString();

                            drvA = double.Parse(pc.GetPower(drvA, dlID, qsrq, jsrq, bm).ToString());

                            mon = "";

                            if (dtDL.Rows[i]["公式"].ToString() != "")
                                mon = drvA.ToString() + dtDL.Rows[i]["公式"].ToString();
                            else
                                mon = drvA.ToString();

                            res = "";
                            try
                            { res = StrHelper.Cale(mon); }
                            catch
                            { res = "0"; }

                            if (id != 0)
                            {
                                zb[id] = dtDL.Rows[i]["参数名"].ToString();
                                un[id] = dtDL.Rows[i]["单位"].ToString();
                                lay[id] = dtDL.Rows[i]["设计值"].ToString();

                                dv[id] += sh.ShowPoint(res, num) + ",";
                                dvExcel[id] += sh.ShowPoint(res, "-1") + ",";
                            }

                            if (ParaID != "")
                            {
                                if (htUn.ContainsKey(ParaID))
                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                else
                                    htUn.Add(ParaID, res);
                            }
                        }
                    }

                    #endregion

                    #region 其它

                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='其它' and 公式级别=" + gsjb;

                    DataTable dtQT = null;

                    if (rlDBType == "SQL")
                        dtQT = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtQT = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtQT.Rows.Count > 0 && dtQT != null)
                    {
                        for (int i = 0; i < dtQT.Rows.Count; i++)
                        {
                            //小数点
                            num = dtQT.Rows[i]["小数点数"].ToString();
                            //参数ID
                            ParaID = dtQT.Rows[i]["参数ID"].ToString();
                            //参数顺序
                            id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                            #region 购网电量
                            if (dtQT.Rows[i]["参数名"].ToString() == "购网电量")
                            {
                                string re = um.gwdl(qsrq, jsrq, 0);

                                if (id != 0)
                                {
                                    zb[id] = dtSQL.Rows[i]["参数名"].ToString();
                                    un[id] = dtSQL.Rows[i]["单位"].ToString();
                                    lay[id] = dtSQL.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(re.ToString(), num) + ",";
                                    dvExcel[id] += sh.ShowPoint(re.ToString(), "-1") + ",";
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                        LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                    else
                                        htUn.Add(ParaID, re);
                                }
                            }
                            #endregion

                            #region 入炉煤低位发热量
                            if (dtQT.Rows[i]["参数名"].ToString() == "入炉煤低位发热量")
                            {
                                string rlm = um.rlmdwfrl("日报", qsrq, jsrq, 1);

                                if (id != 0)
                                {
                                    zb[id] = dtQT.Rows[i]["参数名"].ToString();
                                    un[id] = dtQT.Rows[i]["单位"].ToString();
                                    lay[id] = dtQT.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(rlm, num) + ",";
                                    dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                }

                                if (ParaID != "")
                                {

                                    if (htUn.ContainsKey(ParaID))
                                        LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                    else
                                        htUn.Add(ParaID, rlm);
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion

                    #region 峰谷比
                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型 in('峰','尖','谷' ,'平') and 公式级别=" + gsjb;

                    dtAvg = null;

                    if (rlDBType == "SQL")
                        dtAvg = DBsql.RunDataTable(sql, out errMsg);
                    else if (rlDBType == "DB2")
                        dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtAvg != null && dtAvg.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtAvg.Rows.Count; i++)
                        {
                            //小数点
                            num = dtAvg.Rows[i]["小数点数"].ToString();
                            //点名
                            pName = dtAvg.Rows[i][repType].ToString();
                            //参数ID
                            ParaID = dtAvg.Rows[i]["参数ID"].ToString();
                            //参数顺序
                            id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());

                            string point = dtAvg.Rows[i]["电量点"].ToString();

                            if (dtAvg.Rows[i]["参数类型"].ToString() == "峰")
                            {
                                res = getDlFGB(point, qsrq, jsrq, "峰");
                                drvA = Convert.ToDouble(res.Split('|')[0]);
                            }

                            if (dtAvg.Rows[i]["参数类型"].ToString() == "平")
                            {
                                res = getDlFGB(point, qsrq, jsrq, "平");
                                drvA = Convert.ToDouble(res.Split('|')[1]);
                            }
                            if (dtAvg.Rows[i]["参数类型"].ToString() == "谷")
                            {
                                res = getDlFGB(point, qsrq, jsrq, "谷");
                                drvA = Convert.ToDouble(res.Split('|')[2]);
                            }
                            if (dtAvg.Rows[i]["参数类型"].ToString() == "尖")
                            {
                                res = getDlFGB(point, qsrq, jsrq, "尖");
                                drvA = Convert.ToDouble(res.Split('|')[3]);
                            }

                            if (id != 0)
                            {
                                zb[id] = dtAvg.Rows[i]["参数名"].ToString();
                                un[id] = dtAvg.Rows[i]["单位"].ToString();
                                lay[id] = dtAvg.Rows[i]["设计值"].ToString();

                                dv[id] += sh.ShowPoint(drvA.ToString(), num) + ",";
                                dvExcel[id] += drvA.ToString() + ",";
                            }

                            if (ParaID != "")
                            {
                                if (htUn.Contains(ParaID))
                                {
                                    string str = htUn[ParaID] + drvA.ToString() + ",";
                                    htUn.Remove(ParaID);
                                    htUn.Add(ParaID, str);
                                }
                                else
                                {
                                    htUn.Add(ParaID, drvA.ToString());
                                }
                            }
                        }
                    }
                    #endregion


                    #region 存储过程

                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='存储过程' and 公式级别=" + gsjb;

                    DataTable dtSP = null;

                    if (rlDBType == "SQL")
                        dtSP = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtSP = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtSP != null && dtSP.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtSP.Rows.Count; i++)
                        {
                            //小数点数
                            num = dtSP.Rows[i]["小数点数"].ToString();
                            //参数顺序
                            id = int.Parse(dtSP.Rows[i]["参数顺序"].ToString());
                            //参数ID
                            ParaID = dtSP.Rows[i]["参数ID"].ToString();

                            string spName = dtSP.Rows[i]["SQL语句"].ToString();

                            if (rlDBType == "SQL")
                                obj = DBsql.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), qsrq, jsrq, "", out errMsg);
                            else
                                obj = DBdb2.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), qsrq, jsrq, "", out errMsg);

                            if (obj != null && obj.ToString() != "")
                            {
                                if (obj.ToString() != "")
                                    res = obj.ToString();
                                else
                                    res = "0";
                            }
                            else
                            { res = "0"; }

                            if (id != 0)
                            {
                                zb[id] = dtSP.Rows[i]["参数名"].ToString();
                                un[id] = dtSP.Rows[i]["单位"].ToString();
                                lay[id] = dtSP.Rows[i]["设计值"].ToString();

                                dv[id] += sh.ShowPoint(res, num) + ",";
                                dvExcel[id] += res + ",";
                            }

                            if (ParaID != "")
                            {
                                if (htUn.ContainsKey(ParaID))
                                {
                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                }
                                else
                                    htUn.Add(ParaID, res);
                            }

                        }
                    }
                    #endregion

                    #region 公式

                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='公式' and 公式级别=" + gsjb;

                    DataTable dtMon = null;

                    if (rlDBType == "SQL")
                        dtMon = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtMon = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtMon != null && dtMon.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtMon.Rows.Count; i++)
                        {
                            //小数点数
                            num = dtMon.Rows[i]["小数点数"].ToString();
                            //参数ID
                            ParaID = dtMon.Rows[i]["参数ID"].ToString();
                            //参数顺序
                            id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());

                            string pMon = dtMon.Rows[i]["公式"].ToString();

                            string paras = dtMon.Rows[i]["公式参数"].ToString();

                            string month = pm.retMon(htGY, htUn, paras, pMon);

                            if (month != "")
                            {
                                res = "";
                                try
                                { res = StrHelper.Cale(month); }
                                catch
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtMon.Rows[i]["参数名"].ToString();
                                    un[id] = dtMon.Rows[i]["单位"].ToString();
                                    lay[id] = dtMon.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ",";
                                    dvExcel[id] += sh.ShowPoint(res, "-1") + ",";
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                        LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "--参数ID--" + ParaID + "----在报表配置表中有重复");
                                    else
                                        htUn.Add(ParaID, res);
                                }
                            }
                        }
                    }
                    #endregion
                }
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----全厂结束!");
            }

            #endregion

            #region 调试模式
            if (TSMS == "yes")
            {
                ArrayList listGy = new ArrayList(htGY.Keys);
                ArrayList listUn = new ArrayList(htUn.Keys);

                listGy.Sort();
                listUn.Sort();

                foreach (string skey in listGy)
                { LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----" + skey + "---" + htGY[skey]); }

                foreach (string skey in listUn)
                { LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----" + skey + "---" + htUn[skey]); }
            }
            #endregion

            list.Add(zb);
            list.Add(un);
            list.Add(lay);
            list.Add(dv);
            list.Add(dvExcel);

            return list;
        }

        /// <summary>
        /// 【芜湖短信日报】
        /// 机组轮转
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="repType"></param>
        /// <param name="pType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <returns></returns>
        public ArrayList RetArrsRepMonthByDX(string repName, string repType, string pType, string qsrq, string jsrq, string qsrqT, string jsrqT, bool isDay)
        {
            int id;
            object obj;
            int ret = 0;
            double drvA = 0;
            double drvB = 0;

            string bm = "";
            string mon = "";
            string res = "";
            string num = "";
            string unit = "";
            string pName = "";
            string dlID = "";

            //基础数据值
            string[] zb = null;
            string[] un = null;
            string[] lay = null;
            string[] dv = null;
            string[] du = null;
            string[] dvT = null;
            string[] duT = null;

            string[] dvExcel = null;
            string[] dvExcelT = null;

            string sDate = "";

            if (isDay == true)
                //sDate = DateTime.Parse(jsrq).ToString("yyyy-MM-dd H:59:59");
                sDate = DateTime.Parse(jsrq).AddSeconds(-1).ToString("yyyy-MM-dd H:mm:ss");
            else
                sDate = DateTime.Parse(jsrq).AddSeconds(-1).ToString("yyyy-MM-dd H:mm:ss");

            string sDateT = DateTime.Parse(jsrqT).AddSeconds(-1).ToString("yyyy-MM-dd H:mm:ss");

            ArrayList list = new ArrayList();

            count = pm.GetCountCyd(repName, 1);
            countKey = pm.GetCountkey(repName, 1);

            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日报开始.......");

            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " count Value=" + count + " countKey Value=" + countKey);

            //try
            //{
            zb = new string[count + 1];
            un = new string[count + 1];
            lay = new string[count + 1];
            dv = new string[count + 1];
            du = new string[countKey + 1];
            dvT = new string[count + 1];
            duT = new string[countKey + 1];

            dvExcel = new string[count + 1];
            dvExcelT = new string[count + 1];

            //直接取出中文描速,单位,设计值
            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=1 and 参数顺序!=0 order by 参数顺序";

            DataTable dtInfo = DBsql.RunDataTable(sql, out errMsg);

            if (dtInfo != null && dtInfo.Rows.Count > 0)
            {
                for (int k = 0; k < dtInfo.Rows.Count; k++)
                {
                    id = int.Parse(dtInfo.Rows[k]["参数顺序"].ToString());

                    zb[id] = dtInfo.Rows[k]["参数名"].ToString();
                    un[id] = dtInfo.Rows[k]["单位"].ToString();
                    lay[id] = dtInfo.Rows[k]["设计值"].ToString();
                }
            }
            else
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 读取[中文描速,单位,设计值]信息失败......");

            //机组数据轮转
            sql = "SELECT DISTINCT 机组 FROM T_sheet_sheetPara where 报表名称='" + repName + "' and 机组!=0";

            DataTable dtLevUnit = DBsql.RunDataTable(sql, out errMsg);

            if (dtLevUnit != null && dtLevUnit.Rows.Count > 0)
            {
                for (int k = 0; k < dtLevUnit.Rows.Count; k++)
                {
                    unit = dtLevUnit.Rows[k]["机组"].ToString();

                    sql = "SELECT DISTINCT 公式级别 FROM T_sheet_sheetPara where 报表名称='" + repName + "' and 机组!=0 and 公式级别!=0";

                    DataTable dtLel = DBsql.RunDataTable(sql, out errMsg);

                    if (dtLel.Rows.Count > 0)
                    {
                        for (int j = 0; j < dtLel.Rows.Count; j++)
                        {
                            string gsjb = dtLel.Rows[j]["公式级别"].ToString();

                            #region 电量
                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='电量' and 公式级别=" + gsjb;

                            DataTable dtDL = DBsql.RunDataTable(sql, out errMsg);

                            if (dtDL.Rows.Count > 0 && dtDL != null)
                            {
                                for (int i = 0; i < dtDL.Rows.Count; i++)
                                {
                                    num = dtDL.Rows[i]["小数点数"].ToString();

                                    dlID = dtDL.Rows[i]["电量点"].ToString();

                                    drvA = double.Parse(pc.GetPower(drvA, dlID, qsrq, jsrq, bm).ToString());

                                    mon = "";
                                    mon = drvA.ToString() + dtDL.Rows[i]["公式"].ToString();

                                    res = "";
                                    try
                                    { res = StrHelper.Cale(mon); }
                                    catch
                                    { res = "0"; }

                                    if (dtDL.Rows[i]["显示"].ToString() == "1")
                                    {
                                        id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());

                                        dv[id] += sh.ShowPoint(res, num) + ",";

                                        dvExcel[id] += sh.ShowPoint(res, "-1") + ",";
                                    }

                                    if (dtDL.Rows[i]["参数ID"].ToString() != "")
                                    {
                                        id = int.Parse(dtDL.Rows[i]["参数key"].ToString());

                                        //if (num == "")
                                        du[id] += dtDL.Rows[i]["参数ID"].ToString() + "," + res + ";";
                                        //else
                                        //    du[id] += dtDL.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, num) + ";";
                                    }

                                    drvB = double.Parse(pc.GetPower(drvB, dlID, qsrqT, jsrqT, bm).ToString());

                                    mon = "";
                                    mon = drvB.ToString() + dtDL.Rows[i]["公式"].ToString();

                                    res = "";
                                    try
                                    { res = StrHelper.Cale(mon); }
                                    catch
                                    { res = "0"; }

                                    if (dtDL.Rows[i]["显示"].ToString() == "1")
                                    {
                                        id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());

                                        dvT[id] += sh.ShowPoint(res, num) + ",";

                                        dvExcelT[id] += sh.ShowPoint(res, "-1") + ",";
                                    }

                                    if (dtDL.Rows[i]["参数ID"].ToString() != "")
                                    {
                                        id = int.Parse(dtDL.Rows[i]["参数key"].ToString());

                                        //if (num == "")
                                        duT[id] += dtDL.Rows[i]["参数ID"].ToString() + "," + res + ";";
                                        //else
                                        //    duT[id] += dtDL.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, num) + ";";
                                    }
                                }
                            }

                            #endregion

                            #region 其它
                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='其它' and 公式级别=" + gsjb;

                            DataTable dtQT = DBsql.RunDataTable(sql, out errMsg);

                            if (dtQT.Rows.Count > 0 && dtQT != null)
                            {
                                for (int i = 0; i < dtQT.Rows.Count; i++)
                                {
                                    num = dtQT.Rows[i]["小数点数"].ToString();

                                    #region 购网电量
                                    if (dtQT.Rows[i]["参数名"].ToString() == "购网电量")
                                    {
                                        string re = um.gwdl(qsrq, jsrq, int.Parse(unit), "mx");

                                        if (dtQT.Rows[i]["显示"].ToString() == "1")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                            dv[id] += sh.ShowPoint(re.ToString(), num) + ",";

                                            dvExcel[id] += sh.ShowPoint(re.ToString(), "-1") + ",";
                                        }

                                        if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                            du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + re.ToString() + ";";
                                        }

                                        //同期
                                        string reT = um.gwdl(qsrqT, jsrqT, int.Parse(unit), "mx");

                                        if (dtQT.Rows[i]["显示"].ToString() == "1")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                            dvT[id] += sh.ShowPoint(reT.ToString(), num) + ",";

                                            dvExcelT[id] += sh.ShowPoint(reT.ToString(), "-1") + ",";
                                        }

                                        if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                            duT[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + reT.ToString() + ";";
                                        }

                                    }
                                    #endregion

                                    #region 入炉煤低位发热量
                                    if (dtQT.Rows[i]["参数名"].ToString() == "入炉煤低位发热量")
                                    {
                                        string rlm = um.rlmdwfrl("月报", qsrq, jsrq, 1);

                                        if (dtQT.Rows[i]["显示"].ToString() == "1")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                            dv[id] += sh.ShowPoint(rlm, num) + ",";

                                            dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                        }

                                        if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                            //if (num == "")
                                            du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + rlm + ";";
                                            //else
                                            //  du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(rlm, num) + ";";
                                        }

                                        string rlmT = um.rlmdwfrl(repType, qsrqT, jsrqT, 1);

                                        if (dtQT.Rows[i]["显示"].ToString() == "1")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                            dvT[id] += sh.ShowPoint(rlmT, num) + ",";

                                            dvExcelT[id] += sh.ShowPoint(rlmT, "-1") + ",";
                                        }

                                        if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                            //if (num == "")
                                            duT[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + rlmT + ";";
                                            //else
                                            //    duT[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(rlmT, num) + ";";
                                        }
                                    }
                                    #endregion

                                    #region K2(q2)
                                    if (dtQT.Rows[i]["参数名"].ToString() == "K2(q2)")
                                    {
                                        string pid = dtQT.Rows[i]["参数ID"].ToString();

                                        string val = "0";
                                        string valT = "0";

                                        val = um.K2(pid, du, int.Parse(unit));
                                        valT = um.K2(pid, duT, int.Parse(unit));

                                        if (dtQT.Rows[i]["显示"].ToString() == "1")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                            dv[id] += sh.ShowPoint(val, num) + ",";

                                            dvExcel[id] += sh.ShowPoint(val, "-1") + ",";

                                            dvT[id] += sh.ShowPoint(valT.ToString(), num) + ",";

                                            dvExcelT[id] += sh.ShowPoint(valT.ToString(), "-1") + ",";
                                        }

                                        if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                        {
                                            id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                            du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + val + ";";
                                            duT[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + valT.ToString() + ";";
                                        }
                                    }
                                    #endregion
                                }
                            }
                            #endregion

                            #region 公式
                            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='公式' and 公式级别=" + gsjb;

                            DataTable dtMon = DBsql.RunDataTable(sql, out errMsg);

                            if (dtMon != null && dtMon.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtMon.Rows.Count; i++)
                                {
                                    num = dtMon.Rows[i]["小数点数"].ToString();

                                    string pMon = dtMon.Rows[i]["公式"].ToString();

                                    string paras = dtMon.Rows[i]["公式参数"].ToString();

                                    string month = pm.retMon(pMon, paras, du, unit);
                                    string monthT = pm.retMon(pMon, paras, duT, unit);

                                    if (month != "")
                                    {
                                        res = "";
                                        try
                                        {
                                            res = StrHelper.Cale(month);
                                            //res = sh.ShowPoint(res, num);
                                        }
                                        catch
                                        { res = "0"; }

                                        if (dtMon.Rows[i]["显示"].ToString() == "1")
                                        {
                                            id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());

                                            dv[id] += sh.ShowPoint(res, num) + ",";

                                            dvExcel[id] += sh.ShowPoint(res, "-1") + ",";
                                        }

                                        if (dtMon.Rows[i]["参数ID"].ToString() != "")
                                        {
                                            id = int.Parse(dtMon.Rows[i]["参数key"].ToString());

                                            //if (num == "")
                                            du[id] += dtMon.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, "-1") + ";";
                                            //else
                                            //    du[id] += dtMon.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, num) + ";";
                                        }
                                    }

                                    if (monthT != "")
                                    {
                                        res = "";
                                        try
                                        {
                                            res = StrHelper.Cale(monthT);
                                            //res = sh.ShowPoint(res, num);
                                        }
                                        catch
                                        { res = "0"; }

                                        if (dtMon.Rows[i]["显示"].ToString() == "1")
                                        {
                                            id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());

                                            dvT[id] += sh.ShowPoint(res, num) + ",";

                                            dvExcelT[id] += sh.ShowPoint(res, "-1") + ",";
                                        }

                                        if (dtMon.Rows[i]["参数ID"].ToString() != "")
                                        {
                                            id = int.Parse(dtMon.Rows[i]["参数key"].ToString());

                                            //if (num == "")
                                            duT[id] += dtMon.Rows[i]["参数ID"].ToString() + "," + res + ";";
                                            //else
                                            //    duT[id] += dtMon.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, num) + ";";
                                        }
                                    }
                                }
                            }

                            #endregion
                        }
                    }
                }
            }
            else
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 读取机组信息失败......");

            //全厂数据
            sql = "SELECT DISTINCT 公式级别 FROM T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 公式级别!=0";

            DataTable dtLevZ = DBsql.RunDataTable(sql, out errMsg);

            if (dtLevZ.Rows.Count > 0)
            {
                for (int j = 0; j < dtLevZ.Rows.Count; j++)
                {
                    string gsjb = dtLevZ.Rows[j]["公式级别"].ToString();

                    #region 电量
                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='电量' and 公式级别=" + gsjb;

                    DataTable dtDL = DBsql.RunDataTable(sql, out errMsg);

                    if (dtDL.Rows.Count > 0 && dtDL != null)
                    {
                        for (int i = 0; i < dtDL.Rows.Count; i++)
                        {
                            num = dtDL.Rows[i]["小数点数"].ToString();

                            dlID = dtDL.Rows[i]["电量点"].ToString();

                            drvA = double.Parse(pc.GetPower(drvA, dlID, qsrq, jsrq, bm).ToString());

                            mon = "";
                            mon = drvA.ToString() + dtDL.Rows[i]["公式"].ToString();

                            res = "";
                            try
                            { res = StrHelper.Cale(mon); }
                            catch
                            { res = "0"; }

                            if (dtDL.Rows[i]["显示"].ToString() == "1")
                            {
                                id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());

                                dv[id] += sh.ShowPoint(res, num) + ",";

                                dvExcel[id] += sh.ShowPoint(res, "-1") + ",";
                            }

                            if (dtDL.Rows[i]["参数ID"].ToString() != "")
                            {
                                id = int.Parse(dtDL.Rows[i]["参数key"].ToString());

                                //if (num == "")
                                du[id] += dtDL.Rows[i]["参数ID"].ToString() + "," + res + ";";
                                //else
                                //    du[id] += dtDL.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, num) + ";";
                            }

                            drvB = double.Parse(pc.GetPower(drvB, dlID, qsrqT, jsrqT, bm).ToString());

                            mon = "";
                            mon = drvB.ToString() + dtDL.Rows[i]["公式"].ToString();

                            res = "";
                            try
                            { res = StrHelper.Cale(mon); }
                            catch
                            { res = "0"; }

                            if (dtDL.Rows[i]["显示"].ToString() == "1")
                            {
                                id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());

                                dvT[id] += sh.ShowPoint(res, num) + ",";

                                dvExcelT[id] += sh.ShowPoint(res, "-1") + ",";
                            }

                            if (dtDL.Rows[i]["参数ID"].ToString() != "")
                            {
                                id = int.Parse(dtDL.Rows[i]["参数key"].ToString());

                                //if (num == "")
                                duT[id] += dtDL.Rows[i]["参数ID"].ToString() + "," + res + ";";
                                //else
                                //    duT[id] += dtDL.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, num) + ";";
                            }
                        }
                    }

                    #endregion

                    #region 其它
                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='其它' and 公式级别=" + gsjb;

                    DataTable dtQT = DBsql.RunDataTable(sql, out errMsg);

                    if (dtQT.Rows.Count > 0 && dtQT != null)
                    {
                        for (int i = 0; i < dtQT.Rows.Count; i++)
                        {
                            num = dtQT.Rows[i]["小数点数"].ToString();

                            #region 购网电量
                            if (dtQT.Rows[i]["参数名"].ToString() == "购网电量")
                            {
                                string re = um.gwdl(qsrq, jsrq, 0, "mx");

                                if (dtQT.Rows[i]["显示"].ToString() == "1")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                    dv[id] += sh.ShowPoint(re.ToString(), num) + ",";

                                    dvExcel[id] += sh.ShowPoint(re.ToString(), "-1") + ",";
                                }

                                if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + re.ToString() + ";";
                                }

                                string reT = um.gwdl(qsrqT, jsrqT, 0, "mx");

                                if (dtQT.Rows[i]["显示"].ToString() == "1")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                    dvT[id] += sh.ShowPoint(reT.ToString(), num) + ",";

                                    dvExcelT[id] += sh.ShowPoint(reT.ToString(), "-1") + ",";
                                }

                                if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                    duT[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + reT.ToString() + ";";
                                }

                            }
                            #endregion

                            #region 入炉煤低位发热量
                            if (dtQT.Rows[i]["参数名"].ToString() == "入炉煤低位发热量")
                            {
                                string rlm = um.rlmdwfrl("月报", qsrq, jsrq, 1);

                                if (dtQT.Rows[i]["显示"].ToString() == "1")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                    dv[id] += sh.ShowPoint(rlm, num) + ",";

                                    dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                }

                                if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                    //if (num == "")
                                    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + rlm + ";";
                                    //else
                                    //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(rlm, num) + ";";
                                }

                                string rlmT = um.rlmdwfrl(repType, qsrqT, jsrqT, 1);

                                if (dtQT.Rows[i]["显示"].ToString() == "1")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                    dvT[id] += sh.ShowPoint(rlmT, num) + ",";

                                    dvExcelT[id] += sh.ShowPoint(rlmT, "-1") + ",";
                                }

                                if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                    //if (num == "")
                                    duT[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + rlmT + ";";
                                    //else
                                    //    duT[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(rlmT, num) + ";";
                                }
                            }
                            #endregion

                            #region K2(q2)
                            if (dtQT.Rows[i]["参数名"].ToString() == "K2(q2)")
                            {
                                string pid = dtQT.Rows[i]["参数ID"].ToString();

                                string val = "0";
                                string valT = "0";

                                val = um.K2(pid, du, 0);
                                valT = um.K2(pid, duT, 0);

                                if (dtQT.Rows[i]["显示"].ToString() == "1")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                    dv[id] += sh.ShowPoint(val, num) + ",";

                                    dvExcel[id] += sh.ShowPoint(val, "-1") + ",";

                                    dvT[id] += sh.ShowPoint(valT.ToString(), num) + ",";

                                    dvExcelT[id] += sh.ShowPoint(valT.ToString(), "-1") + ",";
                                }

                                if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                {
                                    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + val + ";";
                                    duT[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + valT.ToString() + ";";
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion

                    #region 公式
                    sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=0 and 参数类型='公式' and 公式级别=" + gsjb;

                    DataTable dtMon = DBsql.RunDataTable(sql, out errMsg);

                    if (dtMon != null && dtMon.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtMon.Rows.Count; i++)
                        {
                            num = dtMon.Rows[i]["小数点数"].ToString();

                            string pMon = dtMon.Rows[i]["公式"].ToString();

                            string paras = dtMon.Rows[i]["公式参数"].ToString();

                            string month = pm.retMon(pMon, paras, du);
                            string monthT = pm.retMon(pMon, paras, duT);

                            if (month != "")
                            {
                                res = "";
                                try
                                {
                                    res = StrHelper.Cale(month);
                                    //res = sh.ShowPoint(res, num);
                                }
                                catch
                                { res = "0"; }

                                if (dtMon.Rows[i]["显示"].ToString() == "1")
                                {
                                    id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());

                                    dv[id] += sh.ShowPoint(res, num) + ",";
                                    dvExcel[id] += sh.ShowPoint(res, "-1") + ",";
                                }

                                if (dtMon.Rows[i]["参数ID"].ToString() != "")
                                {
                                    id = int.Parse(dtMon.Rows[i]["参数key"].ToString());

                                    //if (num == "")
                                    du[id] += dtMon.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, "-1") + ";";
                                    //else
                                    //    du[id] += dtMon.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, num) + ";";

                                }
                            }

                            if (monthT != "")
                            {
                                res = "";
                                try
                                {
                                    res = StrHelper.Cale(monthT);
                                    //res = sh.ShowPoint(res, num);
                                }
                                catch
                                { res = "0"; }

                                if (dtMon.Rows[i]["显示"].ToString() == "1")
                                {
                                    id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());

                                    dvT[id] += sh.ShowPoint(res, num) + ",";
                                    dvExcelT[id] += sh.ShowPoint(res, "-1") + ",";
                                }

                                if (dtMon.Rows[i]["参数ID"].ToString() != "")
                                {
                                    id = int.Parse(dtMon.Rows[i]["参数key"].ToString());

                                    //if (num == "")
                                    duT[id] += dtMon.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, "-1") + ";";
                                    //else
                                    //  duT[id] += dtMon.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(res, num) + ";";

                                }
                            }
                        }
                    }

                    #endregion
                }
            }

            //}
            //catch (Exception ce)
            //{ LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 程序异常: " + ce.Message); }

            for (int i = 1; i < du.Length; i++)
            {
                if (du[i] != null)
                    LogHelper.WriteLog(LogHelper.EnLogType.Success, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + du[i].ToString());
            }

            for (int i = 1; i < dv.Length; i++)
            {
                if (dv[i] != null)
                    LogHelper.WriteLog(LogHelper.EnLogType.Warn, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + dv[i].ToString());
            }

            list.Add(zb);
            list.Add(un);
            list.Add(lay);
            list.Add(dv);
            list.Add(dvT);
            list.Add(dvExcel);
            list.Add(dvExcelT);

            return list;
        }


        /// <summary>
        /// 化学日报
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <returns></returns>
        public ArrayList RetArrsRepHourHX(string repName, int unit, DateTime date, bool isDay)
        {
            string bm = "";
            string mon = "";
            string res = "";
            string num = "";
            string pName = "";
            string dlID = "";
            string repType = "小时点";
            int hours = 0;

            int ret = 0;
            int id;
            object obj;
            double drvA = 0;
            double drvB = 0;
            string sDate = "";

            //基础数据值
            string[] zb = null;
            string[] un = null;
            string[] lay = null;
            string[] dv = null;
            string[] du = null;
            string[] dvExcel = null;

            DateTime dtNow = DateTime.Now;

            ArrayList list = new ArrayList();

            if (isDay == true)
                hours = dtNow.Hour + 1;
            else
                hours = 24;

            count = pm.GetCountCyd(repName, 1);
            countKey = pm.GetCountkey(repName, 1);

            zb = new string[count + 1];
            un = new string[count + 1];
            lay = new string[count + 1];
            dv = new string[count + 1];
            du = new string[countKey + 1];

            dvExcel = new string[count + 1];

            //直接取出中文描速,单位,设计值
            sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=1 and 参数顺序!=0 order by 参数顺序";

            DataTable dtInfo = DBsql.RunDataTable(sql, out errMsg);

            if (dtInfo != null && dtInfo.Rows.Count > 0)
            {
                for (int k = 0; k < dtInfo.Rows.Count; k++)
                {
                    id = int.Parse(dtInfo.Rows[k]["参数顺序"].ToString());

                    zb[id] = dtInfo.Rows[k]["参数名"].ToString();
                    un[id] = dtInfo.Rows[k]["单位"].ToString();
                    lay[id] = dtInfo.Rows[k]["设计值"].ToString();
                }
            }
            else
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 读取[中文描速,单位,设计值]信息失败......");

            try
            {

                #region 平均
                sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='平均' and 公式级别=1";

                DataTable dtAvg = DBsql.RunDataTable(sql, out errMsg);

                if (dtAvg != null && dtAvg.Rows.Count > 0)
                {
                    for (int i = 0; i < dtAvg.Rows.Count; i++)
                    {
                        num = dtAvg.Rows[i]["小数点数"].ToString();

                        pName = dtAvg.Rows[i][repType].ToString();

                        for (int j = 0; j < 24; j++)
                        {
                            sDate = date.AddHours(+j).ToString("yyyy-MM-dd H:59:59");

                            if (DateTime.Parse(sDate) < dtNow && pName != "")
                                ek.GetHisValueByTime(pName, sDate, ref ret, ref drvA);
                            else
                                drvA = 0;

                            if (dtAvg.Rows[i]["显示"].ToString() == "1")
                            {
                                id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());

                                dv[id] += sh.ShowPoint(drvA.ToString(), num) + ",";

                                dvExcel[id] += drvA.ToString() + ",";
                            }
                        }
                    }
                }
                #endregion

                #region 公式
                sql = "select * from T_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " and 参数类型='公式' and 公式级别=1";

                DataTable dtMon = DBsql.RunDataTable(sql, out errMsg);

                if (dtMon != null && dtMon.Rows.Count > 0)
                {
                    for (int i = 0; i < dtMon.Rows.Count; i++)
                    {
                        for (int j = 0; j < 24; j++)
                        {
                            if (dtMon.Rows[i]["显示"].ToString() == "1")
                            {
                                id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());

                                dv[id] += "-,"; //sh.ShowPoint("-9.99", num) + ",";
                            }
                        }
                    }
                }

                #endregion

            }
            catch (Exception ce)
            {
            }
            list.Add(zb);
            list.Add(un);
            list.Add(lay);
            list.Add(dv);
            list.Add(dvExcel);

            return list;
        }

        #region 峰谷比电量计算
        /// <summary>
        /// 峰谷比电量计算
        /// </summary>
        /// <param name="id"></param>
        /// <param name="sTime"></param>
        /// <param name="eTime"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public string getDlFGB(string id, string sTime, string eTime, string title)
        {
            string dl = "";
            string fzTimes = "";
            string pzTimes = "";
            string gzTimes = "";
            string jzTimes = "";

            string[] fzTime = null;
            string[] pzTime = null;
            string[] gzTime = null;
            string[] jzTime = null;

            double fzdl = 0;
            double pzdl = 0;
            double gzdl = 0;
            double jzdl = 0;

            DataTable dt = new DataTable();
            //返回结果  电量  峰 平 谷 尖
            ArrayList list = new ArrayList();

            string sql = "";
            sql = "select * from 时段数据表 where 日期 between '" + Convert.ToDateTime(sTime) + "' and '" + Convert.ToDateTime(eTime).AddSeconds(-1) + "' order by 日期";
            if (rlDBType == "SQL")
                dt = DBsql.RunDataTable(sql, out errMsg);
            else
                dt = DBdb2.RunDataTable(sql, out errMsg);

            if (dt == null || dt.Rows.Count <= 0)
            {
                if (rlDBType == "SQL")
                {
                    sql = "select top 1 * from 时段数据表 where 日期<'" + DateTime.Now + "' order by 日期 desc";
                    dt = DBsql.RunDataTable(sql, out errMsg);
                }
                else
                {
                    sql = "select * from 时段数据表 where 日期<'" + DateTime.Now + "' order by 日期 desc fetch first 1 rows only";
                    dt = DBdb2.RunDataTable(sql, out errMsg);
                }
            }

            #region 取到 峰谷时间戳
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (title == "峰")
                    {
                        fzTimes += dt.Rows[0]["峰值"].ToString().Trim() + ";";
                    }
                    else if (title == "谷")
                    {
                        gzTimes = dt.Rows[0]["谷值"].ToString().Trim() + ";";
                    }
                    else if (title == "平")
                    {
                        pzTimes = dt.Rows[0]["平值"].ToString().Trim() + ";";
                    }
                    else if (title == "尖")
                    {
                        jzTimes = dt.Rows[0]["尖值"].ToString().Trim() + ";";
                    }
                }


                if (title == "峰")
                {
                    fzTimes = fzTimes.Substring(0, fzTimes.Length - 1);
                    fzTime = fzTimes.Split(';');
                    fzdl += getDLFGPJ(id, sTime, eTime, fzTime);
                }
                else if (title == "谷")
                {
                    gzTimes = gzTimes.Substring(0, gzTimes.Length - 1);
                    gzTime = gzTimes.Split(';');
                    gzdl += getDLFGPJ(id, sTime, eTime, gzTime);
                }
                else if (title == "平")
                {
                    pzTimes = pzTimes.Substring(0, pzTimes.Length - 1);
                    pzTime = pzTimes.Split(';');
                    pzdl += getDLFGPJ(id, sTime, eTime, pzTime);
                }
                else if (title == "尖")
                {
                    jzTimes = jzTimes.Substring(0, jzTimes.Length - 1);
                    jzTime = jzTimes.Split(';');
                    jzdl += getDLFGPJ(id, sTime, eTime, jzTime);
                }
            }
            #endregion

            //电量计算
            dl = fzdl + "|" + pzdl + "|" + gzdl + "|" + jzdl;
            return dl;
        }
        public double getDLFGPJ(string dlID, string sTime, string eTime, string[] times)
        {
            string bmStime = "";
            string bmEtime = "";
            //电量
            double dl = 0;
            double sdl = 0;
            double edl = 0;
            //表码值
            object sbm = null;
            object ebm = null;
            //换表表码
            object hbsbm = null;
            object hbebm = null;

            double sumSbm = 0;
            double sumEbm = 0;
            for (int i = 0; i < times.Length; i++)
            {
                string sHour = times[i].Split('-')[0];
                string eHour = times[i].Split('-')[1];

                if (Convert.ToInt32(sHour) < 10 && Convert.ToInt32(sHour) > 0)
                {
                    sHour = "0" + sHour;
                }
                else if (Convert.ToInt32(sHour) == 0)
                {
                    sHour = "00";
                }

                if (Convert.ToInt32(eHour) < 10)
                {
                    eHour = "0" + eHour;
                }
                else if (Convert.ToInt32(eHour) == 24)
                {
                    eHour = "00";
                }

                if (rlDBType == "SQL")
                {
                    bmStime = " and char(时间) like '%-" + sHour + "%'";
                    bmEtime = " and char(时间) like '%-" + eHour + "%'";
                }
                else
                {
                    bmStime = " and char(时间) like '%-" + sHour + ".%'";
                    bmEtime = " and char(时间) like '%-" + eHour + ".%'";
                }

                string sqlsbm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备表码数据表 where  设备ID='" + dlID + "' and 时间 between '" + sTime + "' and '" + Convert.ToDateTime(eTime).AddSeconds(-1) + "'" + bmStime;
                string sqlebm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备表码数据表 where  设备ID='" + dlID + "' and 时间 between '" + Convert.ToDateTime(sTime).AddSeconds(1) + "' and '" + eTime + "'" + bmEtime;
                string sqlhbsbm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备换表起码数据表 where  设备ID='" + dlID + "' and 时间 between '" + sTime + "' and '" + Convert.ToDateTime(eTime).AddSeconds(-1) + "'" + bmStime;
                string sqlhbebm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备换表起码数据表 where  设备ID='" + dlID + "' and 时间 between '" + Convert.ToDateTime(sTime).AddSeconds(1) + "' and '" + eTime + "'" + bmEtime;

                if (rlDBType == "SQL")
                {
                    sbm = DBsql.RunSingle(sqlsbm, out errMsg);
                    ebm = DBsql.RunSingle(sqlsbm, out errMsg);
                    hbsbm = DBsql.RunSingle(sqlhbsbm, out errMsg);
                    hbebm = DBsql.RunSingle(sqlhbebm, out errMsg);
                }
                else
                {
                    sbm = DBdb2.RunSingle(sqlsbm, out errMsg);
                    ebm = DBdb2.RunSingle(sqlebm, out errMsg);
                    hbsbm = DBdb2.RunSingle(sqlhbsbm, out errMsg);
                    hbebm = DBdb2.RunSingle(sqlhbebm, out errMsg);
                }
                if (sbm != null)
                    if (hbsbm != null)
                        sumSbm = Convert.ToDouble(sbm.ToString()) + Convert.ToDouble(hbsbm.ToString());
                    else
                        sumSbm = Convert.ToDouble(sbm.ToString());

                if (ebm != null)
                    if (hbebm != null)
                        sumEbm = Convert.ToDouble(ebm.ToString()) + Convert.ToDouble(hbebm.ToString());
                    else
                        sumEbm = Convert.ToDouble(ebm.ToString());

                sdl += sumSbm;
                edl += sumEbm;
            }

            //倍率
            string sqlbl = "SELECT 倍率 FROM ADMINISTRATOR.设备倍率表 where 设备ID='" + dlID + "'";
            double bl = 1;
            //表码上限
            string sqlbmsx = "SELECT 表码上限 FROM ADMINISTRATOR.设备表码上限表 where 设备ID='" + dlID + "'";
            double sx = 0;

            if (rlDBType == "SQL")
            {
                bl = Convert.ToDouble(DBsql.RunSingle(sqlbl, out errMsg).ToString());
                sx = Convert.ToDouble(DBsql.RunSingle(sqlbmsx, out errMsg).ToString());
            }
            else
            {
                bl = Convert.ToDouble(DBdb2.RunSingle(sqlbl, out errMsg).ToString());
                sx = Convert.ToDouble(DBdb2.RunSingle(sqlbmsx, out errMsg).ToString());
            }

            if (edl - sdl >= 0)
            {
                dl = (edl - sdl) * bl;
            }
            else
            {
                dl = (edl - sdl + sx) * bl;
            }
            return dl;
        }
        #endregion

        #region 四舍五入
        /// <summary>
        /// 四舍五入
        /// </summary>
        /// <param name="result">要转换的数值</param>
        /// <param name="num">保留位数</param>
        /// <returns></returns>
        public double getDouble(double result, int num)
        {
            string res = result.ToString();
            string results = "";
            int index = res.IndexOf('.');

            if (res.Length - index == num + 1)
                return Convert.ToDouble(res);
            else
            {
                if (index > 0)
                {
                    index += num;
                    res = res + "000000000000000000";
                    res = res.Remove(0, index + 1);
                    results = result + "000000000000000000";
                    results = results.ToString().Substring(0, index + 1);
                    res = res.Substring(0, 1);

                    string point = "0.";

                    for (int count = 0; count < num - 1; count++)
                    {
                        point += "0";
                    }
                    point += "1";


                    if (Convert.ToInt32(res) > 4)
                    {
                        results = (Convert.ToDouble(results) + Convert.ToDouble(point)).ToString();
                        res = results;
                    }
                    else
                    {
                        res = results;
                    }
                }
                else
                {
                    res += ".";
                    for (int i = 0; i < num; i++)
                    {
                        res += "0";
                    }
                }
                return Convert.ToDouble(res);
            }
        }
        #endregion
    }
}
